package reconstruction;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;

public class TheReconstruction {
	public static void pl(Object string) {
		pl(string);
	}

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int action = 0; // Used to determine the action a user wishes to take
		int tomeonecheck = 0; // Checks to see if user can use command 8
		String actobj = "blank"; // Used to determine the object a user
		// wishes to act on
		String ExCon; // Checks if user can access extra content
		int menucheck = 0; // Allows loops to repeat menus after actions are
		// complete

		pl("[]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}");
		pl("[]                   }");
		pl("[])                  }");
		pl("[])     The          }");
		pl("[])                  }");
		pl("[]  Reconstruction __}");
		pl("[]                /  |)");
		pl("[]               | D |)");
		pl("[]               | } |)");
		pl("[]     	          \\__|)");
		pl("[]      Book         }");
		pl("[])                  }");
		pl("[])      I           }");
		pl("[])                  }");
		pl("[]                   }");
		pl("[]///////////////////}");

		pl("\nWelcome! Please select an option from the list below!");
		pl("1 - Start New Game");
		pl("2 - Extra Content");
		pl("3 - Exit Game");

		do {

			action = in.nextInt();
			try {

				switch (action) {
				case 1:

					pl("{///////////////////[]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}");
					pl("{                   []                   }");
					pl("{     Foreward      [] in lower case and }");
					pl("{                   [] hit enter. The <> }");
					pl("{  The controls for [] mark targets!     }");
					pl("{ this tale are not [] Basic Actions:    }");
					pl("{ complex. Whenever [] 1 - Walk          }");
					pl("{ an 'Action?' pops [] 2 - Get           }");
					pl("{ up, type a number [] 3 - Bash          }");
					pl("{ for an action you [] 4 - Hack          }");
					pl("{ want to take then [] 5 - Speak         }");
					pl("{ hit enter. Do the [] 6 - Look          }");
					pl("{ same on 'Object?' [] 7 - Use           }");
					pl("{ and type the name []                   }");
					pl("{                   []                   }");
					pl("{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\[]///////////////////}");

					double time = 0;
					while (time < 1000000000) {
						time = time + 1;
					}

					Introduction(action, actobj, tomeonecheck, menucheck); // Takes
					// user
					// to
					// the
					// Intro
					// section
					break;

				case 2: // checks to see if the game has been completed for
					// extra content
					try {
						FileReader input = new FileReader("ReconSave.txt");
						BufferedReader bufRead = new BufferedReader(input);
						ExCon = bufRead.readLine();
						bufRead.close();

						if (ExCon.compareTo("9698163716460084") == 0) {
							pl("Congratulations! You have unlocked the Bonus Content!");
							pl(" Let sleeping dragons lie! ");
							pl("     _________---------_____------____         ");
							pl("    /_______    ---________ -----____ \\       ");
							pl("     /___-- ------_____    ----_____\\_/_      ");
							pl("     /        ___      -----___ ___//   \\__     ");
							pl("    /    ___-/   )            \\-----/     \\ \\  ");
							pl("   |    /        |           __/             | ");
							pl("  /    /    //   |          /    ___   )_ |  | ");
							pl("  |   |     |  _/  _       \\  __/ _ \\//      | ");
							pl("   \\  ----__>_<---/_\\____ __--    =  ___   _/ ");
							pl("    \\----____ ---___-_  /_|_____  __/   /--    ");
							pl("             \\------__> \\-------|/|/---\\\\  ");

						}
					}

					catch (IOException e) {
						pl("Error with file!");
					}

					break;

				case 3:
					System.exit(0);
					break;

				default:
					pl("You need to pick one of the options!");
					break;

				}
			}

			catch (InputMismatchException e) {
				pl("Error.");
				menucheck = 0;
			}

		} while (action != 3);

	}

	public static void Introduction(int action, String actobj,
			int tomeonecheck, int menucheck) {
		pl("");
		pl("{///////////////////[]\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\}");
		pl("{                   []                   }");
		pl("{     Prolouge      []  Our story begins }");
		pl("{       <<>>        [] in the small port }");
		pl("{                   [] of Ceatia. It was }");
		pl("{       _____       [] here that, at the }");
		pl("{     _/_\\_\\_\\      [] end of a long sea }");
		pl("{    /\\\\_     \\     [] journey, the sage }");
		pl("{    \\___>_(_> |    [] Raine disembarked }");
		pl("{       \\_____/     [] her ship to start }");
		pl("{                   [] her hunts for the }");
		pl("{                   [] five scripts lost }");
		pl("{                   [] centuries ago, at }");
		pl("{                   [] the dawn of time. }");
		pl("{                   []                   }");
		pl("{\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\[]///////////////////}");

		double time = 0;
		while (time < 1000000000) {
			time = time + 1;
		}

		pl("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
		pl("After a fortnight of travel arcoss the stormy seas, the vessel you are riding on arrives in port. The ship is in great disorder from the rough travel, and the crew immediately goes to work on it.");
		pl("");
		pl("You are asleep in your quarters under the ship's deck. Your room is very ornate, but then again, it is a government boat. The calmed rocking of the floor allows you to sleep peacefully.");
		pl("");
		pl("'Master! Master! We've arrived in Ceatia! Come on and get up, you lazy sage!'");
		pl("");
		pl("As your eyes open, a familiar glow hovers above you, chiming wildly. You sit up, quickly changing out of your bed clothes and rushing up top to see your destination.");
		pl("");
		pl("Near the door that exits from below deck, you encounter a man dressed in battle armor and wielding a sword. He smiles at you, and begins to speak.");
		pl("'Ah, Miss Raine. I've been waiting for you to arrive. The captain says that The Requiem won't be able to sail for a while. In the mean time, we can go looking for this tome of yours.'");
		pl("");
		pl("He leads you to the ramp off of the ship and into the port town of Ceatia. Even though it appears to be early morning, the town is already alive with traffic.");

		do {
			try {

				Ceatia(action, actobj, tomeonecheck, menucheck); // Takes
				// user to
				// the
				// section
				// Ceatia
			} catch (InputMismatchException e) {
				pl("Error.");
				menucheck = 0;
			} catch (IOException e) {
				pl("MY error.");
				menucheck = 0;
			}

		} while (menucheck == 0);
	}

	public static void Ceatia(int action, String actobj, int tomeonecheck,
			int menucheck) throws IOException {
		Scanner in = new Scanner(System.in);
		Scanner twin = new Scanner(System.in);

		do {

			Inn ceainn = new Inn(); // Object that utilizes class Inn
			TownExit ceaexit = new TownExit(); // Object that utilizes class
			// TownExit
			Boat rship = new Boat(); // Object that utilizes class Boat

			pl("\nYou are now standing in a slight crowded town square, busy with the morning rush. Down the street, at the dock, your <boat> is anchored and being repaired. Along side the road, an <inn> is situated for use by travelers for rest. At the far end of the road, what appears to be a <townexit> gate sits open.");

			/*
			 * Format of selection section...
			 * 
			 * 
			 * 
			 * do{ menucheck = 1; try{ pl("\nAction?"); action = in.nextInt(); <-
			 * User Input for Int of an action }
			 * 
			 * catch(NumberFormatException e) { pl("Invalid Input!"); }
			 * 
			 * pl("\nObject?"); actobj = twin.nextLine(); <- User Input for
			 * Strin of object
			 * 
			 * 
			 * 
			 * switch(action) {
			 * 
			 * case (1 - 9):
			 * 
			 * if(actobj.compareTo("obj1")==0) <-Checks for affected objects {
			 * obj1.action(); menucheck = 1; }
			 * 
			 * if(actobj.compareTo("obj1")==0 && tomeonecheck == 1) <-Checks for
			 * affected objects and if user can use action 8 { obj1.action();
			 * menucheck = 1; }
			 * 
			 * if(actobj.compareTo("locationexit")==0) { locationexit.action();
			 * pl(""); <- If it is a Walk action for exit, then text appears
			 * 
			 * do{
			 * 
			 * try{ Locat(action, actobj, tomeonecheck, menucheck); <- Passes
			 * 'globals' to new function and executes }
			 * 
			 * catch(InputMismatchException e) { pl("Error."); menucheck = 0; }
			 * catch(IOException e) { pl("MY error."); menucheck = 0; }
			 * 
			 * }while(menucheck==0); menucheck = 0; }
			 * 
			 * if(menucheck!=1) { menucheck = 1; }
			 * 
			 * break; }
			 * 
			 * }while(menucheck==1); <-Runs unless menucheck becomes 0, when
			 * user leaves area
			 * 
			 */

			do {
				menucheck = 1;
				try {
					pl("\nAction?");
					action = in.nextInt();
				}

				catch (NumberFormatException e) {
					pl("Invalid Input!");
				}

				pl("\nObject?");
				actobj = twin.nextLine();

				switch (action) {

				case 1:// Walk

					if (actobj.compareTo("inn") == 0) {
						ceainn.walk();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.walk();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.walk();
						pl("\nAfter leaving the town gates, a short stretch of path lay before you until the forest enterance. From the outside, you can feel a dark power resonating from within the wooden thicks. With thoughts of the truths that lay within, you step into the dark forest.");

						do {

							try {
								Forest(action, actobj, tomeonecheck, menucheck);
							}

							catch (InputMismatchException e) {
								pl("Error.");
								menucheck = 0;
							} catch (IOException e) {
								pl("MY error.");
								menucheck = 0;
							}

						} while (menucheck == 0);
						menucheck = 0;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 2:// Get

					if (actobj.compareTo("inn") == 0) {
						ceainn.get();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.get();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.get();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 3:// Bash

					if (actobj.compareTo("inn") == 0) {
						ceainn.bash();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.bash();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.bash();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 4:// Hack

					if (actobj.compareTo("inn") == 0) {
						ceainn.hack();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.hack();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.hack();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 5:// Speak

					if (actobj.compareTo("inn") == 0) {
						ceainn.speak();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.speak();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.speak();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 6:// Look

					if (actobj.compareTo("inn") == 0) {
						ceainn.look();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.look();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.look();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 7:// Use

					if (actobj.compareTo("inn") == 0) {
						ceainn.use();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0) {
						rship.use();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0) {
						ceaexit.use();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 8:// Blast

					if (actobj.compareTo("inn") == 0 && tomeonecheck == 1) {
						ceainn.blast();
						menucheck = 1;
					}

					if (actobj.compareTo("boat") == 0 && tomeonecheck == 1) {
						rship.blast();
						menucheck = 1;
					}

					if (actobj.compareTo("townexit") == 0 && tomeonecheck == 1) {
						ceaexit.blast();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				default:
					break;
				}

			} while (menucheck == 1);

		} while (menucheck == 0);

	}

	public static void Forest(int action, String actobj, int tomeonecheck,
			int menucheck) throws IOException {
		int vinecheck = 0; // checks to see if vine is present or not
		menucheck = 0;
		Scanner in = new Scanner(System.in);
		Scanner twin = new Scanner(System.in);

		do {

			Cave forcave = new Cave(); // Object that utilizes class Cave
			Vine forvine = new Vine(); // Object that utilizes class Vine
			ForestExit forex = new ForestExit(); // Object that utilizes
			// class ForestExit

			System.out
					.println("\nInside the forest, branches blanket the sky, the canopy blocking a great deal of the sunlight from entering. A bit forward on the path, you see a <vine> collection hanging from a cliff face. If you turn around, the <forestexit> is quite obvious to see as well.");

			do {

				try {

					pl("\nAction?");
					action = in.nextInt();
				}

				catch (NumberFormatException e) {
					pl("Invalid Input!");
				}

				pl("\nObject?");
				actobj = twin.nextLine();

				switch (action) {

				case 1:// Walk

					if (actobj.compareTo("vine") == 0) {
						forvine.walk();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && vinecheck == 1) // checks
					// if
					// vine
					// is
					// removed
					{
						if (vinecheck != 0) {
							do {

								forcave.walk();
								System.out
										.println("\nYou stummble down the dark cavernous tunnel for a while, your ally helping you along to make sure that you reach the other side unscathed. The tunnel winds for a while, but you eventually see light up ahead.");

								try {
									Cave(action, actobj, tomeonecheck,
											menucheck);
								}

								catch (InputMismatchException e) {
									pl("Error.");
									menucheck = 0;
								} catch (IOException e) {
									pl("MY error.");
									menucheck = 0;
								}

							} while (menucheck == 0);

							menucheck = 0;
						}
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.walk();
						menucheck = 0;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 2:// Get

					if (actobj.compareTo("vine") == 0) {
						forvine.get();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && vinecheck == 1) {
						forcave.get();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.get();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 3:// Bash

					if (actobj.compareTo("vine") == 0) {
						forvine.bash();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && vinecheck == 1) {
						forcave.bash();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.bash();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 4:// Hac

					if (actobj.compareTo("vine") == 0) {
						forvine.hack();
						vinecheck = 1; // removes vine
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && vinecheck == 1) {
						forcave.hack();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.hack();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 5:// Speak

					if (actobj.compareTo("vine") == 0) {
						forvine.speak();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && vinecheck == 1) {
						forcave.speak();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.speak();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 6:// Look

					if (actobj.compareTo("vine") == 0) {
						forvine.look();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0) {
						forcave.look();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.look();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 7:// Use

					if (actobj.compareTo("vine") == 0) {
						forvine.use();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && vinecheck == 1) {
						forcave.use();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0) {
						forex.use();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 8:// Blast

					if (actobj.compareTo("vine") == 0 && tomeonecheck == 1) {
						forvine.blast();
						menucheck = 1;
					}

					if (actobj.compareTo("cave") == 0 && tomeonecheck == 1
							&& vinecheck == 1) {
						forcave.blast();
						menucheck = 1;
					}

					if (actobj.compareTo("forestexit") == 0
							&& tomeonecheck == 1) {
						forex.blast();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				default:
					break;
				}

			} while (menucheck == 1);

		} while (menucheck == 0);
	}

	public static void Cave(int action, String actobj, int tomeonecheck,
			int menucheck) throws IOException {
		int keycheck = 0; // labels key as not in possession
		int doorcheck = 0; // labels door as open
		int vasecheck = 0; // labels vase as whole
		Scanner in = new Scanner(System.in);
		Scanner twin = new Scanner(System.in);
		// Scanner unlock = new Scanner(System.in); // used to label use of key

		do {

			System.out
					.println("\nThe tunnel opens into a large chamber, which appears to be the front gate of an ancient temple, just like the one you were looking for! In the center of the chamber sits a <vase>, white as the moon at night. Across the way, a <door> sits, sealed, with a lock on it. The <caveexit> behind you is wide open as well.");
			Door cavdoor = new Door(); // Object that utilizes class Door
			Keyit cavkey = new Keyit(); // Object that utilizes class Keyit
			Vase cavvase = new Vase(); // Object that utilizes class Vase
			OpenDoor cavopdoor = new OpenDoor(); // Object that utilizes
			// class OpenDoor
			CaveExit cavex = new CaveExit(); // Object that utilizes class
			// CaveExit

			do {

				try {

					pl("\nAction?");
					action = in.nextInt();
				}

				catch (NumberFormatException e) {
					pl("Invalid Input!");
				}

				pl("\nObject?");
				actobj = twin.nextLine();

				switch (action) {

				case 1:// Walk

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.walk();
						}

						if (doorcheck == 1) {
							cavopdoor.walk();
							do {

								System.out
										.println("The hall goes for a very short distance before light can be seen up ahead. You urge your companion to catch up, and step into the large open chamber beyond.");

								try {
									CaveBook(action, actobj, tomeonecheck,
											menucheck);
								}

								catch (InputMismatchException e) {
									pl("Error.");
									menucheck = 0;
								}
								/*
								 * catch(IOException e) { pl("MY error.");
								 * menucheck = 0; }
								 */
							} while (menucheck == 0);
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						cavvase.walk();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.walk();
						Forest(action, actobj, tomeonecheck, menucheck);
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) // Checks
					// if
					// vase
					// is
					// 'broken'
					{
						cavkey.walk();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 2:// Get

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.get();
						}

						if (doorcheck == 1) {
							cavopdoor.get();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						cavvase.get();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.get();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) {
						cavkey.get();
						keycheck = 1;
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 3:// Bash

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.bash();
						}

						if (doorcheck == 1) {
							cavopdoor.bash();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						if (vasecheck == 0) {
							cavvase.bash();
							vasecheck = 1; // Sets vase as 'broken'
						}

						else {
							System.out
									.println("The vase seems to already be broken... hmmm...");
						}
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.bash();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) {
						cavkey.bash();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 4:// Hac

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.hack();
						}

						if (doorcheck == 1) {
							cavopdoor.hack();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						cavvase.hack();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.hack();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) {
						cavkey.hack();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 5:// Speak

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.speak();
						}

						if (doorcheck == 1) {
							cavopdoor.speak();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						cavvase.speak();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.speak();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) {
						cavkey.speak();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 6:// Look

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.look();
						}

						if (doorcheck == 1) {
							cavopdoor.look();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						cavvase.look();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.look();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) {
						cavkey.look();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 7:// Use

					if (actobj.compareTo("door") == 0) {
						if (doorcheck == 0) {
							cavdoor.use();
						}

						if (doorcheck == 1) {
							cavopdoor.use();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0) {
						cavvase.use();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0) {
						cavex.use();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1) {
						if (keycheck == 1) {
							cavkey.use();
							actobj = twin.nextLine();
							if (actobj.compareTo("door") == 0) {
								doorcheck = 1;
								System.out
										.println("You put the key in the door's keyhole. A crimmson glow bursts forth, and the door rumbles, moving out of the way.");
								keycheck = 0;
							}

							else {
								System.out
										.println("The key cannot be used on that!");
							}

						}
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				case 8:// Blast

					if (actobj.compareTo("door") == 0 && tomeonecheck == 1) {
						if (doorcheck == 0) {
							cavdoor.blast();
						}

						if (doorcheck == 1) {
							cavopdoor.blast();
						}
						menucheck = 1;
					}

					if (actobj.compareTo("vase") == 0 && tomeonecheck == 1) {
						cavvase.blast();
						menucheck = 1;
					}

					if (actobj.compareTo("caveexit") == 0 && tomeonecheck == 1) {
						cavex.blast();
						menucheck = 1;
					}

					if (actobj.compareTo("key") == 0 && vasecheck == 1
							&& tomeonecheck == 1) {
						cavkey.blast();
						menucheck = 1;
					}

					if (menucheck != 1) {
						menucheck = 1;
					}

					break;

				default:
					break;
				}

			} while (menucheck == 1);

		} while (menucheck == 0);
	}

	public static void CaveBook(int action, String actobj, int tomeonecheck,
			int menucheck) {
		Scanner in = new Scanner(System.in);
		Scanner twin = new Scanner(System.in);
		Scanner gem1 = new Scanner(System.in); // All four are used as inputs
		// for the ghost riddle
		Scanner gem2 = new Scanner(System.in);
		Scanner gem3 = new Scanner(System.in);
		Scanner gem4 = new Scanner(System.in);
		Ghost druone = new Ghost(); // Object that utilizes class Ghost
		Bookit tomeone = new Bookit(); // Object that utilizes class Bookit
		GameExit lasex = new GameExit(); // Object that utilizes class
		// GameExit
		Gate bokgat = new Gate(); // Object that utilizes class Gate
		String geminput;
		ArrayList<String> ridansw = new ArrayList<String>(4); // Sets an
																// ArrayList for
		// the riddle
		ridansw.add("");
		ridansw.add("");
		ridansw.add("");
		ridansw.add("");

		String gemoutput;
		// int roundz = 0;
		int gatecheck = 0;

		if (tomeonecheck == 0) {
			System.out
					.println("This room is ornately tiled, seemingly built in honor of someone past. According to your studies, the script should be here. Suddenly, above an odd symbol, a <ghost> appears. At the other end of the chamber, a rusted iron <gate> with a tattered <book> behind it. The <altarexit> remains behind you.");
		}

		else {
			System.out
					.println("This room is ornately tiled, seemingly built in honor of someone past. According to your studies, the script should be here. An odd symbol is engraved in the floor tiles at the room's center. At the other end of the chamber, a rusted iron <gate> which is damaged. The <altarexit> remains behind you.");
		}

		do {
			try {

				pl("Action?");
				action = in.nextInt();
			}

			catch (NumberFormatException e) {
				pl("Invalid Input!");
			}

			pl("Object?");
			actobj = twin.nextLine();

			switch (action) {

			case 1:// Walk

				if (actobj.compareTo("ghost") == 0) {
					druone.walk();

				}
				if (actobj.compareTo("book") == 0 && tomeonecheck == 0) // Makes
				// sure
				// you
				// haven't
				// accquired
				// book
				{
					tomeone.walk();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					if (gatecheck == 2) {
						System.out
								.println("You're stuck behind the gate! You can't reach the exit!");
					}

					else {

						lasex.walk();

						if (tomeonecheck == 1) {
							System.out
									.println("With the first tome in hand, you exit the shrine and travel back into the world above. Many dangers await you on your quest ahead, but for now, you have attained the first of the tomes. Good luck!");
							try // Saves game data to unlock bonus content
							{
								File outFile = new File("ReconSave.txt");
								BufferedWriter writer = new BufferedWriter(
										new FileWriter(outFile));
								pl("...");
								writer.write("9698163716460084");
								writer.close();
							}

							catch (IOException e) {
								pl("Error with file!");
							}

							System.exit(0);
						}

						try {
							Cave(action, actobj, tomeonecheck, menucheck);
						}

						catch (InputMismatchException e) {
							pl("Error.");
							menucheck = 0;
						} catch (IOException e) {
							pl("MY error.");
							menucheck = 0;
						}

					}

					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.walk();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 2:// Get

				if (actobj.compareTo("ghost") == 0) {
					druone.get();
					menucheck = 1;
				}

				if (actobj.compareTo("book") == 0) {
					if (gatecheck == 1 && tomeonecheck == 0) {
						tomeone.get();
						tomeonecheck = 1;
						gatecheck = 2;
					}

					else {

						if (gatecheck == 0) {
							System.out
									.println("The gate is blocking you from accquiring the tome...");
						}

						if (tomeonecheck == 1) {
							System.out
									.println("You've already accquired the tome...");
						}
					}
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					lasex.get();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.get();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 3:// Bash

				if (actobj.compareTo("ghost") == 0) {
					druone.bash();
					menucheck = 1;
				}

				if (actobj.compareTo("book") == 0 && tomeonecheck == 0) {
					tomeone.bash();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					lasex.bash();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.bash();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 4:// Hac

				if (actobj.compareTo("ghost") == 0) {
					druone.hack();
					menucheck = 1;
				}

				if (actobj.compareTo("book") == 0 && tomeonecheck == 0) {
					tomeone.hack();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					lasex.hack();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.hack();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 5:// Speak

				if (actobj.compareTo("ghost") == 0) {
					druone.speak();

					System.out
							.println("'The combination of wards that keeps these halls protected must be known by the wielder of the tome. What is this combination?'");
					System.out
							.println("Spirit:Input one name at a time, and press enter, then input the next, until the ghost responds.'");

					geminput = gem1.nextLine(); // Recieve user input for riddle
					ridansw.set(0, "" + geminput);
					geminput = gem2.nextLine();
					ridansw.set(1, "" + geminput);
					geminput = gem3.nextLine();
					ridansw.set(2, "" + geminput);
					geminput = gem4.nextLine();
					ridansw.set(3, "" + geminput);

					pl("'So...'" + ridansw);

					gemoutput = ridansw.get(0); // Sets the arraylist section to
					// a String

					if (gemoutput.compareTo("pearl") == 0) // Checks if the
					// answer is
					// correct, and
					// repeats
					{
						gemoutput = ridansw.get(1);

						if (gemoutput.compareTo("ruby") == 0) {
							gemoutput = ridansw.get(2);

							if (gemoutput.compareTo("jade") == 0) {
								gemoutput = ridansw.get(3);

								if (gemoutput.compareTo("onyx") == 0) {
									System.out
											.println("'You have correctly learned the warding symbols. Go and claim your prize!'");
									gatecheck = 1;
								}

								else {
									System.out
											.println("'Incorrect. Try again!'");
								}

							}

							else {
								pl("'Incorrect. Try again!'");
							}

						}

						else {
							pl("'Incorrect. Try again!'");
						}
					}

					else {
						pl("'Incorrect. Try again!'");
					}
					menucheck = 1;
				}

				if (actobj.compareTo("book") == 0 && tomeonecheck == 0) {
					tomeone.speak();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					lasex.speak();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.speak();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 6:// Look

				if (actobj.compareTo("ghost") == 0) {
					druone.look();
					menucheck = 1;
				}

				if (actobj.compareTo("book") == 0 && tomeonecheck == 0) {
					tomeone.look();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					lasex.look();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.look();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 7:// Use

				if (actobj.compareTo("ghost") == 0) {
					druone.use();
					menucheck = 1;
				}

				if (actobj.compareTo("book") == 0 && tomeonecheck == 0) {
					tomeone.use();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0) {
					lasex.use();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0) {
					bokgat.use();
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			case 8:// Blast

				if (actobj.compareTo("ghost") == 0 && tomeonecheck == 1) {
					druone.blast();
					menucheck = 1;
				}

				if (actobj.compareTo("altarexit") == 0 && tomeonecheck == 1) {
					lasex.blast();
					menucheck = 1;
				}

				if (actobj.compareTo("gate") == 0 && tomeonecheck == 1) {
					bokgat.blast();
					gatecheck = 0;
					menucheck = 1;
				}

				if (menucheck != 1) {
					menucheck = 1;
				}

				break;

			default:
				break;
			}

		} while (menucheck == 1);
	}

}